<?php
require_once("projectView.php");
require_once(CORE_DIR.'projectModel.php');
require_once(CORE_DIR.'permissionModel.php');

class addAction extends authAction{

	function __construct(){
		$this->view = new projectView();
	}

	public function run($get, $post, $viewtype) {
		parent::run($get,$post,$viewtype);
		
		$pModel = new projectModel();		
		$permModel = new permissionModel();		
		
		if (isset($get["title"])){
			$prjName = $get["title"];	
			$lastInsertId = $pModel->addProject($prjName);	
			$status = 0;
			$id = 0;
			if ($lastInsertId > 0){
				$status = 1;
				$id = $lastInsertId;
			}
			
			if (isset($get["useridlist"]))
				$permModel->addPermissionsToProj($id, $get["useridlist"]);
			
			
			$this->view->setProperty("status", $status);
			$this->view->setProperty("id", $id);
			$this->view->showAddProject();
		}
		else{
			$this->view->showBadCmd();
		}	
			
	}
}
?>